package com.example.xmpic.ui.activity.local;

import com.google.android.material.tabs.TabLayout;
import androidx.fragment.app.Fragment;
import android.text.TextUtils;

import com.example.common.base.BaseBindActivity;
import com.example.common.base.MyPagerAdapter;
import com.example.xmpic.R;
import com.example.xmpic.databinding.ActivityLocalPicVideoBinding;
import com.example.xmpic.ui.fragment.LocalPictureFragment;
import com.example.xmpic.ui.fragment.LocalVideoFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * @author skygge
 * @date 2019-12-22.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：查看本地图片和录像
 */
public class CameraLocalFileActivity extends BaseBindActivity<ActivityLocalPicVideoBinding> {

    private List<Fragment> mFragments; //Tab页面
    private String[] mTitle; //Tab页面标题
    private String mDevSN; //设备序列号

    @Override
    protected int getLayoutId() {
        return R.layout.activity_local_pic_video;
    }

    @Override
    protected void initialize() {
        super.initialize();
        mDevSN = getIntent().getStringExtra("FUN_DEVICE_SN");
        if(TextUtils.isEmpty(mDevSN)){
            showToast(getString(R.string.device_not_exist));
            finish();
        }
    }

    @Override
    protected void initView() {
        super.initView();
        mFragments = new ArrayList<>();
        mTitle = new String[]{getString(R.string.local_pic), getString(R.string.local_video)};
    }

    @Override
    protected void initData() {
        super.initData();
        mFragments.add(LocalPictureFragment.newInstance(mDevSN));
        mFragments.add(LocalVideoFragment.newInstance(mDevSN));
        MyPagerAdapter mAdapter = new MyPagerAdapter(getSupportFragmentManager());
        mAdapter.setTitleAndFragment(mFragments);
        mDBind.vPager.setAdapter(mAdapter);
        mDBind.localTabLayout.addTab(mTitle[0]);
        mDBind.localTabLayout.addTab(mTitle[1]);
        mDBind.localTabLayout.setupWithViewPager(mDBind.vPager);
    }

    @Override
    protected void initListener() {
        super.initListener();
        mDBind.ivRecordBack.setOnClickListener(view -> finish());
        mDBind.localTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        mDBind.vPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(mDBind.localTabLayout.getTabLayout()));
    }
}
